let stageList = []
const modules = import.meta.glob('../stage/**/!(*index).js', { eager: true })
Object.values(modules).forEach(key => {
  const mod = key.default || []
  const modList = Array.isArray(mod) ? mod : [mod]
  stageList.push(...modList)
})
const deepTravel = (config, fuc) => {
  if (config.hidden) {
    return
  }
  if (Array.isArray(config)) {
    config.forEach(item => {
      deepTravel(item, fuc)
    })
    return
  }
  if (config.children && config.children.length) {
    config.name = Symbol(config.name)
    const { children, ...val } = config
    if (val.component) {
      fuc(val)
    } else {
      fuc({ ...val, redirect: config.redirect || `${config.path}/${children[0].path}` })
    }
    config.children.forEach(item => {
      item.path = `${config.path}/${item.path}`
      deepTravel(item, fuc)
    })
    return
  }
  config.name = Symbol(config.name)
  fuc(config)
}
const stageRoutes = []
deepTravel(stageList, item => {
  stageRoutes.push(item)
})

export { stageList, stageRoutes }
